<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			.con{
				text-align: center;
				
			}
			
		</style>
		<script type="text/javascript">
			//1.记录状态,灯亮还是灯灭
			//2.if(is亮) 
			var flag=false;
			function fun(){
				let img=document.querySelector(".con>img");
				let text=document.querySelector(".con>h1");
				if(flag){//灯开着的
					img.setAttribute("src","../src/off.png");
					text.innerText="灯灭了！";
					text.setAttribute("style","color:black")
					flag=false;
				}else{
					img.setAttribute("src","../src/on.png");
					text.innerText="灯亮了！"
					text.setAttribute("style","color:red;")
					flag=true;
				}
				
			}
		</script>
	</head>
	<body>
		<div class="con" onclick="fun()">
		<img src="../src/off.png"  width="200px"/>
		<h1>点击开灯</h1>
		</div>
	</body>
</html>
